package com.tencent.yumeko;

import com.tencent.cloud.common.metadata.StaticMetadataManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/router")
public class MiddleController {

    @Value("${spring.application.name}")
    private String appName;

    @Autowired
    private BackendService backendService;

    @Autowired
    private StaticMetadataManager staticMetadataManager;

    /**
     * Get information of callee.
     *
     * @return information of callee
     */
    @GetMapping("/rest")
    public String rest() {
        String featureEnv = staticMetadataManager.getMergedStaticMetadata().get("featureenv");

        String curName = appName + "[" + featureEnv + "]";
        String resp = backendService.rest();

        return curName + " -> " + resp;
    }
}
